$(function () {
    $('#taskCode').focus();
    //重置表单
    $("#searchReset").on("click",function(){
        $('#taskCode').val('');
        $('#taskName').val('');
        $('#taskTable').bootstrapTable('refresh');
    });
    //渲染表格
    var columns = taskList.columnsInit();
    var table = taskList.gridInit(columns);
    var datas = taskList.dataInit();
    $("#taskTable").bootstrapTable("append",datas);
    //点击删除按钮信息弹出框
    $("#del-btn").click(function(){
        var len = $("#taskTable input:checked").length;
        if (len == 0) {
            //未选中数据提示框
            layer.msg('请选择数据',  {time:1000});
        } else {
            layer.confirm('确定要删除这条数据吗？',
                {icon: 3, title: '提示', area: '300px', btnAlign: 'c'}, function (index) {
                    layer.close(index);
                });
        }

    });
})
;(function(undefined) {
    "use strict"
    var _global;

    function result(args,fn){
        var argsArr = Array.prototype.slice.call(args);
        if(argsArr.length > 0){
            return argsArr.reduce(fn);
        } else {
            return 0;
        }
    }
    var taskList = {
        columnsInit:function(){
            return  [{
                field: 'id',
                title: '序号',
                width:'2%',
                align:'center',
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },{
                field: 'taskGroup',
                valign: 'middle',
                title: '任务分组'
            }, {
                field: 'taskCode',
                valign: 'middle',
                title: '任务编码',
                sortable : true
            }, {
                field: 'taskName',
                valign: 'middle',
                title: '任务名称'
            },{
                field: 'taskHs',
                title: '执行时分秒',
                valign: 'middle',
                align: 'center'
            },{
                field: 'status',
                title: '任务状态',
                valign: 'middle',
                align: 'center',
                formatter: function (value, row, index) {
                    if(value == '启用'){
                        return [
                            '<span class="sys-type-bg pro-status-green">启用</span>'
                        ];
                    }
                    return [
                        '<span class="sys-type-bg pro-status-red">停用</span>'
                    ];

                }

            }, {
                field: 'taskMain',
                title: '是否主任务'

            },{
                checkbox: true
            },{
                field: 'option',
                title: '操作',
                width: 80,
                align: 'center',
                formatter: function (value, row, index) {
                    //up菜单向上展示、 down向下展示
                    var pageSize = taskList.pageSize;
                    var cssStyle = 'bottom';
                    if (index > pageSize / 3) {
                        cssStyle = 'top';
                    }
                    return [
                        '<div class="opt-dropdown tb-opt-div"><a class="tb-opt-icon" href="javascript:void(0)">操作 <i class="glyphicon glyphicon-triangle-bottom"></i></a>',
                        '<ul class="opt-dropdown-menu opt-dropdown-menu-bottom">',
                        '<li><a href="j_task_add.html" title="编辑">',
                        '<i class="glyphicon glyphicon-pencil"></i><em> 编辑</em></a></li>',
                        '<li><a href="j_task_data_list.html"><i class="qxticon icon-sblx"></i><em> 设备</em></a></li></ul></div>'
                    ].join('');
                }

            }]
        },
        gridInit:function(columns){
            return $("#taskTable").bootstrapTable({
                url:'',
                columns: columns,
                striped: 'true',
                classes: 'table table-hover qxttable',
                pagination: 'true',
                pageNumber: 1,
                pageSize: 10,
                pageList: [
                	 10, 20, 50, 100
                ],
                onPostBody:function () {
                    $(".opt-dropdown").hover(function(){
                        $(this).find(".opt-dropdown-menu").show();
                    },function(){
                        $(this).find(".opt-dropdown-menu").hide();
                    })
                }
            })

        },
        dataInit:function(){
            return  [{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'停用',
                taskMain:'否'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            },{
                taskGroup: '任务组',
                taskCode: 'ELE-JFPG-A1',
                taskName:'电表-尖10:00-11:00',
                taskHs:'11:10:02',
                status:'启用',
                taskMain:'是'
            }]
        }
    }

    // 将插件对象暴露给全局对象
    _global = (function(){ return this || (0, eval)('this'); }());
    if (typeof module !== "undefined" && module.exports) {
        module.exports = taskList;
    } else if (typeof define === "function" && define.amd) {
        define(function(){return taskList;});
    } else {
        !('plugin' in _global) && (_global.taskList = taskList);
    }
}());